from django import newforms as forms
from django.shortcuts import render_to_response
from chmouel.travel.models import Destination, City
from django.http import HttpResponseRedirect
import settings


def test(request):
    return render_to_response('travel/test.dhtml')

def index(request, pid=None):
    destinations=Destination.objects.all().order_by('-arrival')

    if pid:
        destination=Destination.objects.get(id=int(pid))
    else:
        destination=destinations[0]

    try:
        previous=destination.get_previous_by_arrival()
    except:
        previous=None

    try:
        next=destination.get_next_by_arrival()
    except:
        next=None

    latitude = destination.city.latitude
    longitude = destination.city.longitude
    satelite_maps = destination.city.satelite_maps
    maps_level = destination.city.maps_level

    if latitude == '0': latitude=None
    if longitude == '0': longitude=None

    args = { 'latitude' : latitude,
             'maps_level' : maps_level,
             'longitude' : longitude,
             'satelite_maps' : satelite_maps,
             'next' : next,
             'destination' : destination,
             'gmap_api_key' : settings.GMAP_API,
             'previous' : previous,
             }

    return render_to_response('travel/index.dhtml', args)
